#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 2e6 + 10;
const int mod = 1e9 + 7;

int a[N], b[N], n, id[N], lef[N];
int nxt[N], fa[N];

int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }

namespace T {
	int fa[N];
	int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
	inline void merge(int x, int y) { x = gf(x); y = gf(y); fa[x] = y; }
	inline void mergeit(int x, int y) { merge(x + n, y); merge(x, y + n); }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif	 
	n = in; rep(i, 1, n) a[i] = in, b[i] = in, id[a[i]] = i, id[b[i]] = i;
	rep(i, 1, 2 * n) {
		if(!lef[id[i]]) lef[id[i]] = i;
		else {
			
}
